﻿using System;
using System.Linq;
using System.Web.Mvc;
using CinemaNetwork.Models;

namespace CinemaNetwork.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private CinemaEntities db = new CinemaEntities();
        public ActionResult Index()
        {
            var cinemas = (from cinema in db.cinemas select cinema).ToList();
            return View(cinemas);
        }

        public ActionResult ViewCinema(int id)
        {
            var films = (from FilmByCinema in db.FilmByCinemas where FilmByCinema.cinemaId == id
                         select FilmByCinema).ToList();
            return View(films);
        }

        public ActionResult ViewSession(int filmId, int cinemaId)
        {
            var sessions = (from SessionByFilmAndCinema in db.SessionByFilmAndCinemas
                         where SessionByFilmAndCinema.cinemaId == cinemaId
                            where SessionByFilmAndCinema.filmId == filmId                
                        select SessionByFilmAndCinema).ToList();
            return View(sessions);
        }

        public ActionResult ViewReservation(int sessionId)
        {
            var reservations = (from Reserv in db.Reservs
                            where Reserv.session_id == sessionId
                            select Reserv).ToList();
            var reservPlace = (from Reservation in db.Reservations
                                where Reservation.session_id == sessionId
                                select Reservation).ToList();
            return View(reservations);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
